package com.api.user.controller;

import com.api.core.annotation.PowerEnable;
import com.api.core.controller.Ctrl;
import com.api.core.response.Result;
import com.api.core.response.ResultGenerator;
import com.api.user.model.Game;
import com.api.user.service.GameService;
import io.swagger.annotations.*;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;


/**
* Created by wanghuiwen on 2021/03/18.
*/
@PowerEnable(name = "Game",url = "/game")
@Api(value = "Game", tags = {"Game"})
@RestController
@RequestMapping("/game")
public class GameController extends Ctrl{
    @Resource
    private GameService gameService;

    @ApiOperation(value = "Game添加", tags = {"Game"}, notes = "Game添加")
    @PostMapping(value="/add",name="Game添加")
    public Result add(@ApiParam Game game) {
        Result result = gameService.add(game);
        return result;
    }

    @ApiOperation(value = "Game删除", tags = {"Game"}, notes = "Game删除")
    @ApiImplicitParams({
        @ApiImplicitParam(name = "id",required=true, value = "Gameid", dataType = "Long", paramType = "query")
    })
    @PostMapping(value="/delete",name="Game删除")
    public Result delete(@RequestParam Long gameId) {

        return gameService.deleteGame(gameId);
    }

    @ApiOperation(value = "Game修改", tags = {"Game"}, notes = "Game修改,对象主键必填")
    @PostMapping(value="/update",name="Game修改")
    public Result update(@ApiParam Game game) {
        gameService.update(game);
        return ResultGenerator.genSuccessResult();
    }

    @ApiOperation(value = "Game详细信息", tags = {"Game"}, notes = "Game详细信息")
    @ApiImplicitParams({
        @ApiImplicitParam(name = "id",required=true, value = "Gameid", dataType = "Long", paramType = "query")
    })
    @PostMapping(value="/detail",name="Game详细信息")
    public Result detail(@RequestParam Integer id) {
        Game game = gameService.findById(id);
        return ResultGenerator.genSuccessResult(game);
    }

    @ApiOperation(value = "Game列表信息", tags = {"Game"}, notes = "Game列表信息")
    @ApiImplicitParams({
        @ApiImplicitParam(name = "search", value = "查询条件json", dataType = "String", paramType = "query"),
        @ApiImplicitParam(name = "order", value = "排序json", dataType = "String", paramType = "query"),
        @ApiImplicitParam(name = "page", value = "页码", dataType = "String", paramType = "query"),
        @ApiImplicitParam(name = "size", value = "每页显示的条数", dataType = "String", paramType = "query", defaultValue = "10")
    })
    @PostMapping(value = "/list", name = "Game列表信息")
    public Result list(@RequestParam(defaultValue = "{}") String search,
                       @RequestParam(defaultValue = "{}") String order,
                       @RequestParam(defaultValue = "0") Integer page,
                       @RequestParam(defaultValue = "10") Integer size) {
        return gameService.list(search, order, page, size);
    }
}
